package basic.demo.array;
//输出杨辉三角-2

/***
 * 输出杨辉三角-2
 * 输出格式：
 * 1
 * 1 1
 * 1 2 1
 * 1 3 3 1
 * ....
 *
 */
public class ArrayStudy7 {


    public static void main(String[] args) {
        int n = 5;
        int[][] arr = new int[n][n];

        for (int i=0; i<n; i++)
            for (int j=0; j<=i; j++) {
                if (j==0 || i==j) {
                    arr[i][j] = 1;
                } else {
                    arr[i][j] = arr[i-1][j] + arr[i-1][j-1];
                }
            }

        for (int i=0; i<n; i++) {
            for (int j=0; j<=i; j++) {
                System.out.print(arr[i][j]+" ");
            }

            //换行
            System.out.println("");
        }

    }


}
